#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve() {
	int n;
	cin >> n;
	vector<ll> v(n + 1);
	for (int i = 1; i <= n; i++) cin >> v[i];

	vector<ll> maxx(n + 1);

	ll curmax = v[1];
	for (int i = 1; i <= n; i++) {
		curmax = max(curmax, v[i]);
		maxx[i] = curmax;
	}


	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 2 == 0) {
			if (v[i] < maxx[i]) {
				v[i] = maxx[i];
			}
			if (v[i - 1] >= v[i]) {
				int x = v[i - 1] - v[i] + 1;
				ans += x;
				v[i - 1] -= x;
			}
			if (i <= n - 1 && v[i + 1] >= v[i]) {
				int x = v[i + 1] - v[i] + 1;
				ans += x;
				v[i + 1] -= x;
			}
		}
	}

	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t;
	cin >> t;
	while (t-- > 0) {
		solve();
	}
	return 0;
}
